<?php
/**
 * 
 * IndexAction.class.php (手机首页)
 *
 * @package      	YOURPHP
 * @author          liuxun QQ:147613338 <admin@yourphp.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.yourphp.cn)
 * @license         http://www.yourphp.cn/license.txt
 * @version        	YourPHP企业网站管理系统 v2.1 2011-03-01 yourphp.cn $
 */
if(!defined("Yourphp")) exit("Access Denied");
class IndexAction extends BaseAction
{
    function _initialize()
    {	
        parent::_initialize();
    }
    /*mobile 手机端 */
    //主页
    public function index() {
        //精品岗位推荐
        $jingpingw = M('gangwei')->where(array('recommend' => 1))->order('listorder asc ,id desc')->limit('4')->select();
        foreach ($jingpingw as $key => $value) {
            $jingpingw[$key]['xmcount'] = M('f_item')->where(array('gwid' => $value['id']))->count();
        }
        $this->assign('jingpingw', $jingpingw);
        //推荐新闻
        $tuijian = M('article')->where(" (recommend = '1' or remen = '1')  and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27') ")->limit(4)->order('listorder asc,id desc')->select();
        $this->assign('tuijian', $tuijian);

        //不推荐新闻
        $notuijian = M('article')->where("( recommend <> '1' and remen <> '1') and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27')  ")->limit(10)->order('listorder asc,id desc')->select();
        $this->assign('notuijian', $notuijian);
        //幻灯片
        $hdp = M('slide_data')->where(array('fid' => '1', 'lang' => '1'))->select();

        foreach ($hdp as $key => $value) {
            $hdimg = thumb($value['pic'], 1920, 360);
            $hdp[$key]['pic'] = $hdimg;
        }
        $this->assign('hdp', $hdp);
        $this->display();
    }

    // 全部课程 -原来主页
    public function allcourse()
    {
        
         //13岗位 12项目 14专业 23电子教案表 22微课表 21任务表 24文档课件表 25素材表
        //$this->getarrbygid('22',4) id查询
        //$this->p($this->getarrbyid('14',id));exit; 列表查询

        $zy=$this->getarrbyid('14');
        foreach ($zy as $key => $value) {
            //岗位集
            $gw=$this->getarrbygid('13',$value['id']['val']); 
            foreach ($gw as $key2 => $value2) {
                //项目集
                //$i=1;
                $gw[$key2]['xmnum']=$this->getnumbygid('12',$value2['id']['val']);
            } 
         
            $zy[$key]['gwlist']=$gw;
        }
        $hdp=M('slide_data')->where(array('fid'=>'1','lang'=>'1'))->select();

         
         $this->assign('menu',json_encode($zy));
         $this->assign('hdp',$hdp);
         
         $this->assign('zy',$zy);
        //  print_r($zy);
         $this->display();
    }
    // 专业 岗位
    public function major()
    {

        $z = $_GET['pid'];

        $c = $_GET['cid'];
        if($c){
            //岗位
            $data = $this->getarrbyid('13',$c)[0];
                    
            //子集数 项目
            $list=$this->getarrbygid('12',$c);

            $dzjcnum=0;
            $jxspnum=0;
            $wkkjnum=0;
            $dzjanum=0;
            $qtkjnum=0;
            $jxscnum=0;
            //set岗位下项目数
            foreach ($list as $k => $vo){
                //任务数
                $list[$k]['childs']['val']  = $this-> getnumbygid('21',$vo['id']['val']);
                
                $jxspnum+=$this->getjxspnum($vo['id']['val']);
                //微课
                $wkkjnum+=$this->getnumbygid('22',$vo['id']['val']);

                $dzjanum+=$this->getnumbygid('23',$vo['id']['val']);
                $qtkjnum+=$this->getnumbygid('24',$vo['id']['val']);

                //素材
                $jxscnum+=$this->getscbnum($vo['id']['val']);
                //$jxscnum+=$this->getnumbygid('25',$vo['id']['val']);
                $dzjcnum+=$this->getnumbygid('21',$vo['id']['val']);
               
               
            }
            
            $data['dzjcnum']=$dzjcnum;
            $data['jxspnum']=$jxspnum;
            $data['wkkjnum']=$wkkjnum;
            $data['dzjanum']=$dzjanum;
            $data['qtkjnum']=$qtkjnum;
            $data['jxscnum']=$jxscnum;
            // $this->p($list);

        }else{

            //专业
            $data = $this->getarrbyid('14',$z)[0];
            
            //子集数
            $list=$this->getarrbygid('13',$z);

            $dzjcnum=0;
            $jxspnum=0;
            $wkkjnum=0;
            $dzjanum=0;
            $qtkjnum=0;
            $jxscnum=0;
            //set专业下岗位数
            foreach ($list as $k => $vo){
                //岗位数
                $list[$k]['childs']['val'] = $this-> getnumbygid('12',$vo['id']['val']);

                $xm=$this->getarrbygid('12',$vo['id']['val']);
                foreach ($xm as $key3 => $value3) {
                    $jxspnum+=$this->getjxspnum($value3['id']['val']);
                    //微课
                    $wkkjnum+=$this->getnumbygid('22',$value3['id']['val']);

                    $dzjanum+=$this->getnumbygid('23',$value3['id']['val']);
                    $qtkjnum+=$this->getnumbygid('24',$value3['id']['val']);

                    //素材
                    $jxscnum+=$this->getscbnum($value3['id']['val']);
                    //$jxscnum+=$this->getnumbygid('25',$value3['id']['val']);
                    $dzjcnum+=$this->getnumbygid('21',$value3['id']['val']);
                }
                 
            }
            $data['dzjcnum']=$dzjcnum;
            $data['jxspnum']=$jxspnum;
            $data['wkkjnum']=$wkkjnum;
            $data['dzjanum']=$dzjanum;
            $data['qtkjnum']=$qtkjnum;
            $data['jxscnum']=$jxscnum;
    
        }
        // $this->p($list);
        //子集列表
        $this->assign('list',$list);
        // $this->p($list);
        //专业id
        $this->assign('pid',$z);
        if($c)$this->assign('cid',$c);
        //当前数据对象
        $this->assign('data',$data);
        $this->display();
    }
         //mobile 详情页
    public function details()
    {
        $o=$_GET['oid'];
        //项目
        $xm = $this->getarrbyid('12',$o);

        $info=$this->getzyid($o);
        // $this->p($xm);
        if(count($xm))$xm = $xm[0];
        //任务开始
        $rw=$this->getarrbygid('21',$o);
          //任务是否为0
        $rwempty = 0;
        foreach ($rw as $vo) {
            if(sizeof($vo["rwsp"]['val'])){
                $rwempty = 1;
                break;
            };
        }
         $this->assign('rw',$rw);
        //任务结束
         //微课开始
        $wk = $this->getarrbygid('22', $o);
        $this->assign('wk', $wk);
        //微课结束
        //电子课件开始
        $kj = $this->getarrbygid('24', $o);
        $this->assign('kj', $kj);
        //电子课件结束
          
        $iskey=$this->getiskey($o);
        $this->assign('iskey',$iskey);

        $jxspnum+=$this->getjxspnum($xm['id']['val']);
        //微课
        $wkkjnum+=$this->getnumbygid('22',$xm['id']['val']);
        $dzjanum+=$this->getnumbygid('23',$xm['id']['val']);
        $qtkjnum+=$this->getnumbygid('24',$xm['id']['val']);
        //素材
        $jxscnum+=$this->getscbnum($xm['id']['val']);
        //$jxscnum+=$this->getnumbygid('25',$xm['id']['val']);
        $dzjcnum+=$this->getnumbygid('21',$xm['id']['val']);
         
        $xm['dzjcnum']=$dzjcnum;
        $xm['jxspnum']=$jxspnum;
        $xm['wkkjnum']=$wkkjnum;
        $xm['dzjanum']=$dzjanum;
        $xm['qtkjnum']=$qtkjnum;
        $xm['jxscnum']=$jxscnum;


        // $gw = $this->getarrbygid('12',$xm['gwid']['val']);


        // // 获得当前在岗位的序号
        // foreach($gw as $k=>$vo){
            
        //     if($vo == $xm){
        $xm['zyid']['val']=$info['pid'];
        $xm['order']['val'] = ($info['xmid']>10?$info['xmid']:'0'.($info['xmid']));
        //         break;
        //     }
        // }

        //任务数
        $rwnum=$this->getnumbygid('21',$o);
        $this->assign('xm',$xm);
         
        $this->assign('rwnum',$rwnum);
        $this->display();
    }

//详情页 任务
    public function material()
    {
        $o=$_GET['oid'];
        $p=$_GET['pid'];
        $c=$_GET['cid'];
        //任务
        $rw=$this->getarrbygid('21',$o);
        $this->assign('oid',$o);
        $this->assign('rw',$rw);
        $this->assign('pid',$p);
        $this->assign('cid',$c);
        
        $this->display();
    }
    //关于 专业 岗位 项目
    public function about()
    {   
        // 专业
        $z = $_GET['pid'];
        // gan岗位
        $c= $_GET['cid'];
        //项目
        $o=$_GET['oid'];

        //数据
       if($o){
            // 项目
           $data=$this->getarrbyid('12',$o);
       }else if($c){
        //    岗位
            $data=$this->getarrbyid('13',$c);

       }else{
        //    专业
            $data=$this->getarrbyid('14',$z);

       }

        $this->assign('data',$data);
        //$this->p($data);
        // 学习场景
        $this->assign('JList',$data[0]['j_list']['val']);
        $this->display();
    }
    // 详情资源
    public function extend()
    {
        $o=$_GET['oid'];
        //电子课件
        $kj = $this->getarrbygid("24",$o);
        //视频
        $rw=$this->getarrbygid('21',$o);
        //微课
        $wk=$this->getarrbygid('22',$o);
        //其他
        $sc=$this->getarrbygid('25',$o);
        $iskey=$this->getiskey($o);
        //个人
        $as = '';
        $bo = "";
         if($this->_ms=='2'&&$iskey)
         {
             $as = $this->getresources(0,$o)[$o];
             $bo = $this->getresources(1,$o)[$o];
        }
        //任务是否为0
        $rwempty = 0;
        foreach ($rw as $vo) {
            if(sizeof($vo["rwsp"]['val'])){
                $rwempty = 1;
                break;
            };
        }
            
        $this->assign('empty',"<p class='col-xs-12'>暂时没有相关数据</p>");
        $this->assign('oid',$o);
        $this->assign('kj',$kj);
        $this->assign('rw',$rw);
        $this->assign('rwempty',$rwempty);
        $this->assign('sc',$sc);
        // $this->p($sc[0]['scwj']['val']);
        $this->assign('iskey',$iskey);
        $this->assign('wk',$wk);
        $this->assign('as',$as);
        $this->assign('bo',$bo);
        //$this->p($wk);
         $this->display();
    }
    // 任务
    public function material_details()
    {
        $o = $_GET['oid'];
        $kid = $_GET['kid'];
        $p=$_GET['pid'];
        $c=$_GET['cid'];
        $tesk=array();
        //任务
        $rw=$this->getarrbygid('21',$o);
        foreach($rw as $k => $vo){

            if($k == $kid){
                $tesk = $vo;
                break;
            }

        }
        //$this->p($tesk);
        $this->assign('rw',$rw);
        $this->assign('oid',$o);
        $this->assign('pid',$p);
        $this->assign('cid',$c);
        $this->assign('kid',$kid);
        $this->assign('tesk',$tesk);
        $this->display();
        
    }
    
     //获取项目排行
    public function getfitem() {
        if ($_POST['aa'] == 'liulan') {
            $list = M('f_item')->order('readpoint desc, id desc')->limit('8')->select();
        } else {
            $list = M('f_item')->order('redu desc, id desc')->limit('8')->select();
        }
        foreach($list as $kk =>$vv){
           $info = M('gangwei')->field('zyid')->where(array('id'=>$vv['gwid']))->find();
           $list[$kk]['zyid'] = $info['zyid'] ;
        }
        echo json_encode($list) ;
        exit ;
    }
    
        //统计
    public function statis() {
        for ($i = -6; $i <= 0; $i++) {
            $riqi[] = date("Y-m-d", strtotime("+".$i." day")) ;
        }
        $data['riqi'] = json_encode($riqi) ;
        $order=array() ;
        $brower=array() ;
        foreach($riqi as $kk=>$vv){
            $order[] = M('actuser')->where(array('riqi'=>$vv))->count() ;
            $shul = M('browstatis')->where(array('riqi'=>$vv))->getfield('num') ;
            $brower[] = !empty($shul) ? $shul : 0 ;
        }
        $data['huoyue'] = json_encode($order) ;
        $data['brower'] = json_encode($brower) ;
        $data['gangwei'] = M('gangwei')->where(array('status' => 1))->count();
        $data['xiangmu'] = M('f_item')->where(array('status' => 1))->count();
        $data['renwu'] = M('renwu')->where(array('status' => 1))->count();
        $data['weike'] = M('weike')->where(array('status' => 1))->count();
         $xxxx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=index&a=user_num',array()),'true') ;
        $data['user'] = $xxxx['total_num'];
        $data['fangwei'] = M('browstatis')->sum('num');
        $this->assign('data', $data);
        $this->display();
    }
    
        //排行
    public function news() {
        //推荐
        $tuijian = M('article')->where( "(recommend = '1' )  and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27') ")->limit(1)->order('listorder asc,id desc')->select();
        $this->assign('tuijian', $tuijian);
         //热门
         $remen = M('article')->where( "(remen = '1' )  and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27') ")->limit(3)->order('listorder asc,id desc')->select();
        $this->assign('remen', $remen);
        //公告
        $gonggao = M('article')->where(array('catid' => 26))->limit(4)->order('listorder asc,id desc')->select();
        $this->assign('gonggao', $gonggao);
        //文件
        $wenjian = M('article')->where(array('catid' => 27))->limit(4)->order('listorder asc,id desc')->select();
        $this->assign('wenjian', $wenjian);
        $this->display();
    }
    
    //获得新闻列表
    public function getnews() {
        $p = empty($_POST['page'])? '1':$_POST['page'] ;
        $firstrow = 0 ;
        $listrows = 10 ;
        $now = $listrows*($p-1) ;
        $list = M('article')->where(" recommend <> '1' and remen <> '1' and catid = '".$_POST['catid']."' ")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        foreach ($list as $key => $value) {
            $list[$key]['createtime'] = date('Y-m-d', $value['createtime']);
            $abc = M('actarticle')->where(array('nid' => $value['id'], 'uid' => $this->_userid,'groupid'=> cookie('groupid')))->find(); 
            $list[$key]['yizan'] = empty($abc) ? '2' : '1' ;
        }
        echo json_encode($list);
    }
    
        //新闻详情页
    public function newsdetails(){
       $info =  M('article')->where(array('id'=>$_GET['id']))->find() ;
        $this->assign('info', $info);
        //浏览增加
        $info =  M('article')->where(array('id'=>$_GET['id']))->setInc('hits') ;
        //公告
        $gonggao = M('article')->where(array('catid' => 26))->limit(4)->order('listorder asc,id desc')->select();
        $this->assign('gonggao', $gonggao);
        $this->display();
    }
    
        //排行
    public function rank() {
        $liulan = M('f_item')->order('readpoint desc')->limit('10')->select();
        foreach ($liulan as $k => $v) {
            $zyid = M('gangwei')->where(array('id' => $v['gwid']))->getField('zyid');
            $liulan[$k]['zyid'] = $zyid;
        }

        $redu = M('f_item')->order('redu desc')->limit('10')->select();
        foreach ($redu as $kk => $vv) {
            $zyidv = M('gangwei')->where(array('id' => $vv['gwid']))->getField('zyid');
            $redu[$kk]['zyid'] = $zyidv;
        }

        for ($i = -6; $i <= 0; $i++) {
            $riqi[] = date("Y-m-d", strtotime("+" . $i . " day"));
        }
        $data['riqi'] = json_encode($riqi);
        $brower = array();
        foreach ($riqi as $kk => $vv) {
            $shul = M('browstatis')->where(array('riqi' => $vv))->getfield('num');
            $brower[] = !empty($shul) ? $shul : 0;
        }
        $data['brower'] = json_encode($brower);


        $this->assign('liulan', $liulan);
        $this->assign('redu', $redu);
        $this->assign('data', $data);
        $this->display();
    }
    
    //播放页面
    public function detailsplay() {
        if (!empty($_GET['rwid'])) {  //教学视频（任务视频）
            $type = 'rwid';
            $xmid = M('renwu')->where(array('id'=>$_GET['rwid']))->getField('xmid') ;
            $typeid = $_GET['rwid'];
            $xiangguan=$this->getarrbygid('21',$xmid);
        }
        if (!empty($_GET['dzjc'])) {  //电子教材（任务教材）
            $type = 'dzjc';
            $xmid = M('renwu')->where(array('id'=>$_GET['dzjc']))->getField('xmid') ;
            $typeid = $_GET['dzjc'];
            $xiangguan=$this->getarrbygid('21',$xmid);
        }
        if (!empty($_GET['wkid'])) {  //微课
            $type = 'wkid';
            $xmid = M('weike')->where(array('id'=>$_GET['wkid']))->getField('xmid') ;
            $typeid = $_GET['wkid'];
            $xiangguan=$this->getarrbygid('22',$xmid);
        }
        if (!empty($_GET['kjid'])) {  //电子课件
            $type = 'kjid';
            $xmid = M('wdkj')->where(array('id'=>$_GET['kjid']))->getField('xmid') ;
            $typeid = $_GET['kjid'];
            $xiangguan=$this->getarrbygid('24',$xmid);
        }
        //print_r($xiangguan) ;
        $this->assign('xmid',$xmid) ;
        //项目id
        $xminfo = M('f_item')->where(array('id'=>$xmid))->find() ;
        $this->assign('xminfo',$xminfo) ;
        //专业id
        $zyid = M('gangwei')->where(array('id'=>$xminfo['gwid']))->getField('zyid') ;
        $this->assign('zyid',$zyid) ;
        
        $this->assign('xiangguan',$xiangguan) ;

        //当前用户是否收藏
        $shoucang = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'uid' => $this->_userid, 'src' => $_GET['file']))->find();
        if(empty($shoucang)){
            $this->assign('tt',2) ;
        }else{
            $this->assign('tt',1) ;
        }
        //收藏的总用户数
        $totalsc = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'src' => $_GET['file']))->count();
        $this->assign('totalsc',$totalsc) ;
        $list = M('videocomment')->where(array('type' => $type, 'typeid' => $typeid,  'src' => $_GET['file']))->order('id desc')->select();
        foreach ($list as $kk=>$vv){
            $acc = M('user')->where(array('id'=>$vv['uid']))->find() ;
            $list[$kk]['account']['realname'] = cookie('realname') ;
            $list[$kk]['account']['avatar'] = cookie('avatar') ;
            $list[$kk]['createtime'] = date('Y-m-d H:i:s',$vv['createtime']) ;
        }

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('typeid', $typeid);
        $this->assign('title', urldecode($_GET['title']));
        $this->assign('file', $_GET['file']);
        $this->display();
    }
    
    //招聘页面
    public function recruit(){
        $list = M('zhuanye')->order('id desc')->select() ;
        $this->assign('list',$list) ;
        $this->display();
    }
    
        //首页获取招聘信息
    public function getindexrecruit() {
        if (!empty($_POST['zhuanye'])) {
            $list = M('recruit')->where(" zhuanye = '" . $_POST['zhuanye'] . "' ")->order('listorder asc,id desc')->select();
        }
        echo json_encode($list);
    }

    //获取招聘信息
    public function getrecruit() {
        $p = empty($_POST['page']) ? '1' : $_POST['page'];
        $firstrow = 0;
        $listrows = 10;
        $now = $listrows * ($p - 1);
        if (!empty($_POST['zhuanye'])) {
            $list = M('recruit')->where(" zhuanye = '" . $_POST['zhuanye'] . "' ")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        } else {
            $list = M('recruit')->where(" (title like '%{$_POST['title']}%') or (workplace like '%{$_POST['title']}%')  or (companyname like '%{$_POST['title']}%') " )->order('listorder asc,id desc')->select();
        }
        echo json_encode($list);
    }
}